# Python中的流程控制语句

# 分支结构
# if 10 > 0:
#     print("10 > 0")

# year = eval(input("请输入年份:"))
# month = eval(input("请输入月份:"))
# day = 0
# if month == 2:
#     if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):  # 闰年
#         day = 29
#     else:  # 平年
#         day = 28
# elif month == 1 or month == 3 or month == 5 \
#         or month == 7 or month == 8 or month == 10 or month == 12:  # 大月
#     day = 31
# else:  # 剩下的全是小月了
#     day = 30
# # print("{}年{}月一共有{}天".format(year, month, day))
# print("%d年%d月一共有%d天" % (year, month, day))

# 循环结构

# ran1 = range(0, 5)  # [0 1 2 3 4]
# ran2 = range(0, 5, 2)  # [0, 2, 4]
# for i in ran1:
#     print(i, end="")
# print()
# for j in ran2:
#     print(j, end="")
# print()
# str1 = "abcde"
# for z in str1:
#     print(z)

# 阶乘之和
# def factorial(n):
#     sum1 = 0
#     num = 1
#     for i in range(1, n + 1):
#         num *= i
#         sum1 += num
#     return sum1
#
#
# n = eval(input("请输入n值："))
# print("从1!到{}!的阶乘和为{}".format(n, factorial(n)))

# 头尾互换：
# list1 = [1, 2, 3, 4]
# head = 0
# tail = len(list1) - 1
# while head < tail:
#     list1[head], list1[tail] = list1[tail], list1[head]
#     head += 1
#     tail -= 1
# print(list1)


# 循环结构里面的else：
# # 比如我们识8为不正常数据，需要break
# for i in range(8):
#     if i == 8:
#         break
# else:
#     print("正常结束")
#
# for i in range(9):
#     if i == 8:
#         break
# else:
#     print("正常结束")


# random()函数默认产生[0,1)的随机数
# 使用蒙特卡罗方法计算圆周率：
# import random
# N = 10000
# n = 0
# for i in range(N):
#     x = random.random() * 2 - 1  # [0, 2) - 1 ..
#     y = random.random() * 2 - 1
#     if x * x + y * y <= 1:
#         n += 1
# print("蒙特卡罗方法预估圆周率为{}".format((4.0 * n / N)))

# 输出数字金字塔

"""
   1
  212
 32123
4321234
"""
# n = eval(input("输入行数:"))
# for i in range(n):
#     print(' ' * (n - i - 1), end="")
#     for j in range(i + 1, 0, -1):
#         print(j, end="")
#     for j in range(2, i + 2):
#         print(j, end="")
#     print()


# for i in range(10, 0, -1):
#     print(i)

# 练习题：

# x = 2
# y = 2.0
# if x == y:
#     print('Y')

# a = 17
# b = 6
# result = a % b if (a % b < 4) else a/b
# print(result)

# 三目运算符
# a = 3
# b = 4
# c = 0
# c = a if a > b else b
# print(c)

# 大小写进行转换
# str1 = "ABcd78ad"
# print(str1)
# print(str1.swapcase())

#  输入一个整数，将其反转
# a = eval(input("输入一个整数："))
# while a != 0:
#     print(a % 10, end="")
#     a //= 10
# print()

# 计算1^2 -2^2 +3^2......+97^2- 98^2 + 99^2
# sum1 = 0
# for i in range(1, 100):
#     if i % 2 == 0:
#         sum1 -= i * i
#     else:
#         sum1 += i * i
# print(sum1)

# print(7 // 2)
# 找出100内的所有完数：（完数就是等于它的因子之和。比如6就是一个完数，6的因子就是1 2 3,6 = 1+2+3）
# def factor(n):
#     sum2 = 0
#     for j in range(1, (n // 2) + 1):
#         if n % j == 0:
#             sum2 += j
#     return sum2
#
#
# for i in range(1, 101):
#     if factor(i) == i:
#         print(i, end=" ")

# 输入两个正整数m和n，求其最大公约数和最小公倍数：
# print("请分别输入两个数：")
# m = eval(input())
# n = eval(input())
# _max = max(m, n)
# _min = min(m, n)
# while True:
#     _min = _max % _min
#     if _min != 0:
#         _max = _min
#     else:
#         break
# print("最大公约数为{},最小公倍数为{:d}".format(_max, (m * n) // _max))

# 输入一元二次方程的3个系数a、b、c,求ax2 + bx + c = 0方程的根
# import math
# print("输入一元二次方程的三个系数：")
# a = eval(input())
# b = eval(input())
# c = eval(input())
# sum1 = b * b - 4 * a * c
# if sum1 < 0:
#     print("无实根")
# else:
#     der = math.sqrt(sum1)
#     print("第一个根为{},第二个根为{}".format(((-b + der) / 2 * a), ((-b - der) / 2 * a)))




